/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.Produccion;

import Atxy2k.CustomTextField.RestrictedTextField;
import Controlador.Bean.Produccion.Receta;
import Controlador.Bean.Produccion.Fase;
import gui.General.Main;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import lib.Validaciones;
/**
 *
 * @author Nadhia
 */
public class detalleProductoHorneado extends javax.swing.JPanel {

    /**
     * Creates new form detalleProductoHorneado
     */
    Receta nr;
   AjusteReceta ar;
    
    public detalleProductoHorneado( Receta nr, AjusteReceta ar) {
   
    this.nr = nr;
    this.ar = ar;
    initComponents();
//    receta.getIdReceta();
    initComp2();
        
    }
    private void initComp2(){
//         setTb2(new TableModel2());
//         tblIngredientes.setModel(getTb2());
//         tblIngredientes.setRowSelectionAllowed(true);
        txtNombre.setText(nr.getNombre());
         txtNombre.setEnabled(false);
         txtIdFase.setEnabled(false);
         RestrictedTextField restricted = new RestrictedTextField(txtHorasH);
         restricted.setLimit(5);
//         restricted.setOnlyNums(true);
         restricted = new RestrictedTextField(txtHorasM);
         restricted.setLimit(5);
//         restricted.setOnlyNums(true);
//         tblProductos.setModel(tb);
//         tblProductos.setRowSelectionAllowed(true);
//         txtIdProducto.setEditable(false);
//         tipos = Controlador.Service.Almacen.GestionAlmacenes.obtenerTipo();
//         cmbTipo.removeAllItems();
//         cmbUnidadMedida.removeAllItems();
//         cmbUnidadMedida.addItem("Seleccionar");
//         cmbUnidadMedida.addItem("Kg.");
//         cmbUnidadMedida.addItem("m.");
//         cmbUnidadMedida.addItem("gr.");
//         cmbUnidadMedida.addItem("Unidades");
//         cmbTipo.addItem("Seleccionar");
//         for(int i=0; i<tipos.size(); i++){
//             cmbTipo.addItem(tipos.get(i).getNombre());
//         }
//         tblProductos.setDefaultRenderer(JButton.class, new MiRender());
//         tblProductos.setDefaultEditor( JButton.class, new MiEditor());
//         btnBuscar.setMnemonic(KeyEvent.VK_F2);
     }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    public int validar(){
        int error = 0;
        boolean vali1 = Validaciones.validarReal(txtHorasH.getText());
        boolean vali2 = Validaciones.validarReal(txtHorasM.getText());
        if(txtHorasH.getText().isEmpty()) {
            error=2;
        }
        else
           if(!vali1){
            error=1;}
           else 
            if (txtHorasM.getText().isEmpty()){
                error=4;
            }
            else
            if(!vali2){
            error=3;}    
                
            
        
//        int indice = (int)cmbTipo.getSelectedIndex();
//        System.out.println("indice...."+indice);
//        System.out.println("fecha...."+jdpFecha.getDate());
//        if(txtNombre.getText().isEmpty()){
//        error=1;}
//        else if((jdpFecha.getDate()== null) || (jdpFecha.getDate().after(today))){
//        error=2; }
//        else if((indice==0))
//        { error=3;  }
//        else if(txtDescripcion.getText().isEmpty()){
////        error=4;    
//        }
        
        
        
        return error;
        
        
    }
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel2 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        txtHorasH = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        txtHorasM = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtDescripcion = new javax.swing.JTextArea();
        txtIdFase = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        btnCancelar = new javax.swing.JButton();
        btnContinuar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        btnSeleccionar = new javax.swing.JButton();
        btnDetalle = new javax.swing.JButton();
        btnSeleccionarPInt = new javax.swing.JButton();

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Masa / Horneado"));
        jPanel2.setAutoscrolls(true);
        jPanel2.setPreferredSize(new java.awt.Dimension(735, 250));

        jLabel4.setText("Nombre Producto:");

        jLabel5.setText("Preparación Masa (horas):");

        txtNombre.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNombreActionPerformed(evt);
            }
        });

        jLabel16.setText("Horas Hombre (horas):");

        txtHorasH.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHorasHActionPerformed(evt);
            }
        });

        jLabel15.setText("Indicaciones:");

        txtHorasM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtHorasMActionPerformed(evt);
            }
        });

        txtDescripcion.setColumns(20);
        txtDescripcion.setRows(5);
        jScrollPane1.setViewportView(txtDescripcion);

        txtIdFase.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtIdFaseActionPerformed(evt);
            }
        });

        jLabel6.setText("Id Fase:");

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        btnContinuar.setText("Continuar");
        btnContinuar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnContinuarActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Receta"));

        btnSeleccionar.setText("Seleccionar Ingredientes");
        btnSeleccionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSeleccionarActionPerformed(evt);
            }
        });

        btnDetalle.setText("Ver detalle");
        btnDetalle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDetalleActionPerformed(evt);
            }
        });

        btnSeleccionarPInt.setText("Seleccionar Producto Salida");
        btnSeleccionarPInt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSeleccionarPIntActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(60, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(btnDetalle)
                        .addGap(80, 80, 80))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(btnSeleccionarPInt, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btnSeleccionar, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(24, 24, 24))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(btnSeleccionar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnDetalle)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSeleccionarPInt))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel16)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtIdFase, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtHorasH, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txtHorasM, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 202, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(26, 26, 26))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnContinuar)
                .addGap(116, 116, 116)
                .addComponent(btnCancelar)
                .addGap(203, 203, 203))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(2, 2, 2)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel15)
                            .addComponent(txtIdFase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addGap(14, 14, 14)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtHorasH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtHorasM, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel5))))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCancelar)
                    .addComponent(btnContinuar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 673, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 232, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void txtIdFaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtIdFaseActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtIdFaseActionPerformed

    private void btnSeleccionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeleccionarActionPerformed
        
        try {

        int error = validar();  
           
           if(error==1){
           JOptionPane.showMessageDialog(this,"Horas hombre debe ser número real", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==2){
               JOptionPane.showMessageDialog(this,"Ingrese Horas hombre", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
            else
               if(error==3){
           JOptionPane.showMessageDialog(this,"Preparación Masa debe ser número real", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==4){
               JOptionPane.showMessageDialog(this,"Ingrese Preparación Masa", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
//               if(vseleccionfases.isEmpty()){
//               JOptionPane.showMessageDialog(this,"Selecciona mínimo un proceso", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
//           } 
//           else
//            if(error==4){
//               JOptionPane.showMessageDialog(this,"Ingrese una descripcion");
//           }  
           else
            if(error==0){
           //         System.out.println("dato.."+cmbTipo.getSelectedIndex());
       //System.out.println("dato.."+cmbTipo.getSelectedIndex()-1);   
       
        
//        agregar receta
//        Double.parseDouble(txtCantidadProducto.getText())
        Fase fa = new Fase(txtIdFase.getText(), nr.getIdReceta(), "Horneado", 1, Double.parseDouble(txtHorasH.getText()), txtDescripcion.getText(),"1",Double.parseDouble(txtHorasM.getText()),"TMA000001");
//        Receta re = new Receta(txtIdReceta.getText(), idBuscar, nombreBuscar, Double.parseDouble(txtCantidadProducto.getText()), " ", txtDescripcion.getText(), "1");
//        Receta re = new Receta(" ", idBuscar, nombreBuscar, 43.4, " ", "hola mundo", "1");
      
        if(txtIdFase.getText().isEmpty()){
           
          try {
            Controlador.Service.Produccion.GestionProduccion.agregarFase(fa);
            txtIdFase.setText(fa.getIdFase());
//            Controlador.Service.Produccion.GestionProduccion.agregarReceta(re);
            System.out.println("efectua la insercion");
//            JOptionPane.showMessageDialog(this,"Se ingreso datos");
            //        para continuar siguiente ventana
            
            agregarIngrediente aip = new agregarIngrediente(nr,fa);
            Main.getDesktop().add(aip);
            aip.setVisible(true);
            
//            AjusteReceta arp = new AjusteReceta( seleccionfases,re);
//             Main.getDesktop().add(arp);
//        ar.actualizar(seleccionfases);
        
//        arp.setVisible(true);
//        this.dispose();
            
        } catch (Exception ex) { 
            System.out.println("nno guarda");
        }
                                          
        }
        else{
            Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
             agregarIngrediente aip = new agregarIngrediente(nr,fa);
            Main.getDesktop().add(aip);
            aip.setVisible(true);
//            JOptionPane.showMessageDialog(this,"Se actualizo datos");
        }
        
        
    
        
        

        
                
//
//        fecha = jdpFecha.getDate();
//        Maquina nm = new Maquina(txtIdMaquina.getText(), txtNombre.getText(),  tipos.get(cmbTipo.getSelectedIndex()-1).getIdTipoMaquina(),  txtDescripcion.getText() , fecha, "1", "1" );
//        
//           
//         tb.actualizarTabla();
//        txtIdMaquina.setText("");
//        txtNombre.setText("");
//        txtDescripcion.setText("");
//        cmbTipo.setSelectedIndex(0);
//        cmbTipo.setEnabled(true);
            }     
            
      
       
//        dpFecha.setDate(today);
         
        } catch (Exception ex) {
        System.out.println("errror"+ex.getMessage());
        System.out.println("errror"+ex);
        }
        
    }//GEN-LAST:event_btnSeleccionarActionPerformed

    private void txtHorasMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHorasMActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHorasMActionPerformed

    private void txtHorasHActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtHorasHActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtHorasHActionPerformed

    private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombreActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNombreActionPerformed

    private void btnContinuarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnContinuarActionPerformed
        // TODO add your handling code here:
        try {

        int error = validar();  
           if(txtIdFase.getText().isEmpty()){
           JOptionPane.showMessageDialog(this,"Debe ingresar ingredientes", "Advertencia", JOptionPane.OK_OPTION); 
           }
           else              
           if(error==1){
           JOptionPane.showMessageDialog(this,"Horas hombre debe ser entero", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==2){
               JOptionPane.showMessageDialog(this,"Ingrese Horas hombre", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
            else
               if(error==3){
           JOptionPane.showMessageDialog(this,"Preparación Masa debe ser entero", "Advertencia", JOptionPane.OK_OPTION);
               
           }
           else 
           if(error==4){
               JOptionPane.showMessageDialog(this,"Ingrese Preparación Masa", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
           }
//               if(vseleccionfases.isEmpty()){
//               JOptionPane.showMessageDialog(this,"Selecciona mínimo un proceso", "Error en ingreso de Datos", JOptionPane.OK_OPTION);
//           } 
//           else
//            if(error==4){
//               JOptionPane.showMessageDialog(this,"Ingrese una descripcion");
//           }  
           else
            if(error==0){
           //         System.out.println("dato.."+cmbTipo.getSelectedIndex());
       //System.out.println("dato.."+cmbTipo.getSelectedIndex()-1);   
       
        
//        agregar receta
//        Double.parseDouble(txtCantidadProducto.getText())
        Fase fa = new Fase(txtIdFase.getText(), nr.getIdReceta(), "Horneado", 1, Double.parseDouble(txtHorasH.getText()), txtDescripcion.getText(),"1",Double.parseDouble(txtHorasM.getText()),"TMA000001");
//        Receta re = new Receta(txtIdReceta.getText(), idBuscar, nombreBuscar, Double.parseDouble(txtCantidadProducto.getText()), " ", txtDescripcion.getText(), "1");
//        Receta re = new Receta(" ", idBuscar, nombreBuscar, 43.4, " ", "hola mundo", "1");
        Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
        JOptionPane.showMessageDialog(null,"Los datos fueron actualizados");
//            JOptionPane.showMessageDialog(this,"Se actualizo datos");
        System.out.println("efectua la actualización");
        
//        if(txtIdFase.getText().isEmpty()){
//           
//          try {
//            Controlador.Service.Produccion.GestionProduccion.agregarFase(fa);
//            txtIdFase.setText(fa.getIdFase());
////            Controlador.Service.Produccion.GestionProduccion.agregarReceta(re);
//            System.out.println("efectua la insercion");
////            JOptionPane.showMessageDialog(this,"Se ingreso datos");
//            //        para continuar siguiente ventana
//            
////            agregarIngrediente aip = new agregarIngrediente(nr,fa);
////            Main.getDesktop().add(aip);
////            aip.setVisible(true);
//            
////            AjusteReceta arp = new AjusteReceta( seleccionfases,re);
////             Main.getDesktop().add(arp);
////        ar.actualizar(seleccionfases);
//        
////        arp.setVisible(true);
////        this.dispose();
//            
//        } catch (Exception ex) { 
//            System.out.println("nno guarda");
//        }
//                                          
//        }
//        else{
//            Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
////            JOptionPane.showMessageDialog(this,"Se actualizo datos");
//            System.out.println("efectua la insercion");
//        }
        
        
    
        
        

        
                
//
//        fecha = jdpFecha.getDate();
//        Maquina nm = new Maquina(txtIdMaquina.getText(), txtNombre.getText(),  tipos.get(cmbTipo.getSelectedIndex()-1).getIdTipoMaquina(),  txtDescripcion.getText() , fecha, "1", "1" );
//        
//           
//         tb.actualizarTabla();
//        txtIdMaquina.setText("");
//        txtNombre.setText("");
//        txtDescripcion.setText("");
//        cmbTipo.setSelectedIndex(0);
//        cmbTipo.setEnabled(true);
            }     
            
      
       
//        dpFecha.setDate(today);
         
        } catch (Exception ex) {
        System.out.println("errror"+ex.getMessage());
        System.out.println("errror"+ex);
        }
    }//GEN-LAST:event_btnContinuarActionPerformed

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
       
            int confirmado = JOptionPane.showConfirmDialog(this,"¿Desea cancelar el producto?");
            if (confirmado == JOptionPane.OK_OPTION){
//              JOptionPane.showMessageDialog(this,"Se actualizo datos");  Controlador.Service.Produccion.GestionProduccion.eliminarProductoxFase((String)tblProductos.getValueAt(selectedRowIndex, 0), fa.getIdFase());
//                JOptionPane.showMessageDialog(this,"No se puede eliminar Ingredientes, crear nueva receta");
                
//                agregarProducto  ap = new agregarProducto(ar, (String)tblProductos.getValueAt(selectedRowIndex, 0),(String)tblProductos.getValueAt(selectedRowIndex, 1));
//                Main.getDesktop().add(ap);
//                ap.setVisible(true);
                String codigoR = nr.getIdReceta();
                Controlador.Service.Produccion.GestionProduccion.cambiarEstadoReceta(codigoR);
                ar.dispose();
//                this.dispose();
                //                Controlador.Service.Almacen.GestionAlmacenes.eliminarProductos((String)tblProductos.getValueAt(selectedRowIndex, 0));
                //                tb.actualizarTabla();
            }
        
            txtIdFase.setText("");
            txtNombre.setText("");
            txtDescripcion.setText("");
            txtHorasH.setText("");
            txtHorasM.setText("");
//            Fase fa = new Fase(txtIdFase.getText(), nr.getIdReceta(), "Horneado", 1, Double.parseDouble(txtHorasH.getText()), txtDescripcion.getText(),"0",Double.parseDouble(txtHorasM.getText()),"TMA000001");
//        
////            Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
//////            JOptionPane.showMessageDialog(this,"Se actualizo datos");
////            System.out.println("efectua la actualización");
//            txtIdFase.setText("");
//            txtNombre.setText("");
//            txtDescripcion.setText("");
//            txtHorasH.setText("");
//            txtHorasM.setText("");
//            JOptionPane.showMessageDialog(this,"Cerrar Ventana Producto Final", "Advertencia", JOptionPane.OK_OPTION);
//           
        
            
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnDetalleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDetalleActionPerformed
        // TODO add your handling code here:
        
       if(txtIdFase.getText().isEmpty()){
           JOptionPane.showMessageDialog(this,"Debe ingresar ingredientes", "Advertencia", JOptionPane.OK_OPTION);
           
       } 
       else{
//            Controlador.Service.Produccion.GestionProduccion.actualizarFase(fa);
//            JOptionPane.showMessageDialog(this,"Se actualizo datos");
           Fase fa = new Fase(txtIdFase.getText(), nr.getIdReceta(), "Horneado", 1, Double.parseDouble(txtHorasH.getText()), txtDescripcion.getText(),"1",Double.parseDouble(txtHorasM.getText()),"TMA000001");
           String codigo = new String(); 
                  codigo = txtIdFase.getText();
           buscarIngrediente bi = new buscarIngrediente(codigo);
           Main.getDesktop().add(bi);
           bi.setVisible(true);
//            System.out.println("efectua la actualización");
        }
        
    }//GEN-LAST:event_btnDetalleActionPerformed

    private void btnSeleccionarPIntActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSeleccionarPIntActionPerformed
        // TODO add your handling code here:
        int error = validar();  
        
           if(txtIdFase.getText().isEmpty()){
           JOptionPane.showMessageDialog(this,"Debe ingresar ingredientes", "Advertencia", JOptionPane.OK_OPTION); 
           }
           else{
               String cod = txtIdFase.getText();
            int cant = Controlador.Service.Produccion.GestionProduccion.cuentaSalida(cod);
            if (cant == 0){
                Fase fa = new Fase(txtIdFase.getText(), nr.getIdReceta(), "Horneado", 1, Double.parseDouble(txtHorasH.getText()), txtDescripcion.getText(),"1",Double.parseDouble(txtHorasM.getText()),"TMA000001");
                agregarIntermedio aint = new agregarIntermedio(nr,fa);
                Main.getDesktop().add(aint);
                aint.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this,"Ya se ingresó un producto salida", "Advertencia", JOptionPane.OK_OPTION);
               
           }
        
    }//GEN-LAST:event_btnSeleccionarPIntActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnContinuar;
    private javax.swing.JButton btnDetalle;
    private javax.swing.JButton btnSeleccionar;
    private javax.swing.JButton btnSeleccionarPInt;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea txtDescripcion;
    private javax.swing.JTextField txtHorasH;
    private javax.swing.JTextField txtHorasM;
    private javax.swing.JTextField txtIdFase;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables
}
